package com.ruoyi.mymod.service.impl;
import com.ruoyi.mymod.service.IPigAiService;
import com.ruoyi.mymod.utils.Dbutil.Qp;

import com.ruoyi.mymod.utils.Dbutil.R;
import org.springframework.stereotype.Service;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;


@Service
public class PigAiServiceImpl implements IPigAiService {

    public String getSowAi(){

        return "";
    }


    @Override
    public String getMessage() throws Exception {
        R r=null;
        Qp qp=null;
        try {

            LocalDate d= LocalTime.now().getHour()> 10 ?
                    LocalDate.now().plusDays(-2):
                    LocalDate.now().plusDays(-2);

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式需要与字符串匹配
//            // 解析字符串为java.util.Date
//            Date utilDate = sdf.parse("2024-09-09");

            // 转换为java.sql.Date（仅包含日期部分）
//            java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

            Date sqlDate = Date.valueOf(d);

            qp = new Qp();
            Object o= qp.setUsrpwd("pigpos","pigpos").
                    setP(sqlDate).funcP(4,"ai.getfinish");
            r=(R) o;

        }finally {
            qp.closeConn();
        }
        return r.json;
    }

    @Override
    public String getYfMessage() throws Exception {
        R r=null;
        Qp qp=null;
        try {

            qp = new Qp();
            Object o= qp.setUsrpwd("pigpos","pigpos").func(4,"ai.getsow");
            r=(R) o;

        }finally {
            qp.closeConn();
        }
        return r.json;
    }

    @Override
    public String getKillMessage() throws Exception {
        R r=null;
        Qp qp=null;
        try {
            qp = new Qp();
            Object o= qp.setHostPortDb("10.104.8.15","1521","orclpdb").setUsrpwd("ctcnxzs","ctcnxzs").func(4,"food.his_pro");
            r=(R) o;
        }finally {
            qp.closeConn();
        }
        return r.json;
    }

}
